using System;
using UnityEngine;

namespace Script.Utilities
{
    public class FollowObj : MonoBehaviour
    {
        [SerializeField] private Transform target;
        [SerializeField] private bool lockX;
        [SerializeField] private bool lockY;
        [SerializeField] private bool lockZ;
        private Vector3 startPos;

        private void Awake()
        {
            startPos = transform.localPosition;
        }

        private void FixedUpdate()
        {
            Vector3 pos;
            pos.x = lockX ? transform.localPosition.x : target.transform.position.x + startPos.x;
            pos.y = lockY ? transform.localPosition.y : target.transform.position.y + startPos.y;
            pos.z = lockZ ? transform.localPosition.z : target.transform.position.z + startPos.z;
            transform.position = pos;
        }
    }
}
